﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace huaguwang.hgmanage.microblog
{
      public partial class microbolgs : PageBaseAdmin
      {
            #region 固定方法

            readonly D_T_MicroBlogging_Exp _Dal = new D_T_MicroBlogging_Exp();

            private void SetBut(int i, Button but)
            {
                  switch (i)
                  {
                        case 0:
                        case 1:
                        case 2:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                              but.Attributes.Add("onclick", "return GetDelCheckDefault();");
                              break;
                        case 4:
                              but.Attributes.Add("onclick", "return GetUpdateCheckDefault();");
                              break;
                        default:
                              break;
                  }
            }
            private huaguwang.WebControls.WebUserToolBar.SelectItem[] SetText()
            {
                  huaguwang.WebControls.WebUserToolBar.SelectItem[] list = { 
                new huaguwang.WebControls.WebUserToolBar.SelectItem(){
                    FuncGetText=()=>TextBox1.Text.Exp_Trim(),
                    FuncSetText=V=>{TextBox1.Text=V;},
                    Name=TextBox1.ID
                },                                                                                                                           
            };
                  return list;
            }
            /// <summary>
            /// 查询的实现方法
            /// </summary>
            /// <param name="begin"></param>
            private void SetData(int begin)
            {
                  AdminPublic.Try(() =>
                  {
                        var p1 = WebUserToolBar1.MainGetQuery(TextBox1.ID);
                        int resultCount = 0;
                        var vList = _Dal.GetConditionMicroBolgs(p1, begin, Pager.PageSize, out resultCount);
                        this.Pager.RecordCount = resultCount;
                        this.Repeater1.DataSource = vList;
                        this.Repeater1.DataBind();
                  });
            }

            #endregion


            protected void Page_Load(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        Pager.PageSize = 10;



                        if (!IsPostBack)
                        {

                        }
                        //用来初始化用户的按钮,执行此语句的时候,but并没有具体产生
                        this.WebUserToolBar1.MainInit(
                            UserConst.Exp_GetUser,
                            UserConst.Exp_GetButtonList,
                            SetBut,
                            UserConst.Exp_ToolBarErr,
                            SetText()
                        );
                        if (!IsPostBack)
                        {
                              SetData(0);
                        }
                  });



            }




            #region 基本的带有查询的事件组合

            /// <summary>
            /// 分页控件的页面事件
            /// </summary>
            /// <param name="src"></param>
            /// <param name="e"></param>
            protected void Pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        SetData((e.NewPageIndex - 1) * Pager.PageSize);
                  });
            }

            /// <summary>
            /// 查询按钮事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void WebUserToolBar1_Button3(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        WebUserToolBar1.MainSetQuery();
                        SetData(0);
                  });
            }
            /// <summary>
            /// 封帖按钮事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void WebUserToolBar1_Button0(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        var intA = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                        if (intA == null || intA.Count <= 0)
                        {
                              this.Exp_PageAlter("没有找到可以封帖的信息");
                              return;
                        }

                        var refInt = _Dal.ChangeMicroBolgState(intA, D_T_MicroBlogging_Exp.FrozenType.封帖);
                        if (refInt > 0)
                        {
                              this.Exp_PageWriteLog(Log_Type.delete, "微博资料", intA);
                              SetData(0);
                              this.Exp_PageAlter("微博资料封帖操作成功");
                              return;
                        }
                        else
                        {
                              this.Exp_PageAlter("微博资料封帖操作失败");
                              return;
                        }
                  });
            }

            /// <summary>
            /// 解帖按钮的事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void WebUserToolBar1_Button1(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        var intA = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                        if (intA == null || intA.Count <= 0)
                        {
                              this.Exp_PageAlter("没有找到可以解帖的信息");
                              return;
                        }

                        var refInt = _Dal.ChangeMicroBolgState(intA, D_T_MicroBlogging_Exp.FrozenType.解帖);
                        if (refInt > 0)
                        {
                              this.Exp_PageWriteLog(Log_Type.delete, "微博资料", intA);
                              SetData(0);
                              this.Exp_PageAlter("微博资料解帖操作成功");
                              return;
                        }
                        else
                        {
                              this.Exp_PageAlter("微博资料解帖操作失败");
                              return;
                        }
                  });
            }
            /// <summary>
            /// 删除按钮的事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void WebUserToolBar1_Button2(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        var intA = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                        if (intA == null || intA.Count <= 0)
                        {
                              this.Exp_PageAlter("没有找到可以删除的信息");
                              return;
                        }

                        var refInt = _Dal.UpdateFlag(intA);
                        if (refInt > 0)
                        {
                              this.Exp_PageWriteLog(Log_Type.delete, "微博资料", intA);
                              SetData(0);
                              this.Exp_PageAlter("微博资料删除操作成功");
                              return;
                        }
                        else
                        {
                              this.Exp_PageAlter("微博资料删除操作失败");
                              return;
                        }
                  });
            }
            #endregion

            /// <summary>
            /// 查看按钮事件 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void WebUserToolBar1_Button4(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var sKey = WebUserToolBar1.MainSetSKey();
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        Response.Redirect("microbolgs_E.aspx?ID=" + strID + "&" + sKey, false);

                  });
            }

            /// <summary>
            /// 推荐按钮事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void WebUserToolBar1_Button5(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        var intA = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                        if (intA == null || intA.Count <= 0)
                        {
                              this.Exp_PageAlter("没有找到可以推荐的信息");
                              return;
                        }

                        var refInt = _Dal.ChangeMicroBolgState(intA, D_T_MicroBlogging_Exp.FrozenType.推荐);
                        if (refInt > 0)
                        {
                              this.Exp_PageWriteLog(Log_Type.other, "微博资料", refInt, "推荐微博");
                              SetData(0);
                              this.Exp_PageAlter("微博资料推荐操作成功");
                              return;
                        }
                        else
                        {
                              this.Exp_PageAlter("微博资料推荐操作失败");
                              return;
                        }
                  });
            }

            /// <summary>
            /// 置顶按钮事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void WebUserToolBar1_Button6(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        var intA = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                        if (intA == null || intA.Count <= 0)
                        {
                              this.Exp_PageAlter("没有找到可以置的信息");
                              return;
                        }

                        var refInt = _Dal.ChangeMicroBolgState(intA, D_T_MicroBlogging_Exp.FrozenType.置顶);
                        if (refInt > 0)
                        {
                              this.Exp_PageWriteLog(Log_Type.other, "微博资料", refInt, "置顶微博");
                              SetData(0);
                              this.Exp_PageAlter("微博资料置操作成功");
                              return;
                        }
                        else
                        {
                              this.Exp_PageAlter("微博资料置操作失败");
                              return;
                        }
                  });
            }
            //不推荐
            protected void WebUserToolBar1_Button7(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        var intA = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                        if (intA == null || intA.Count <= 0)
                        {
                              this.Exp_PageAlter("没有找到可以不推荐的信息");
                              return;
                        }

                        var refInt = _Dal.ChangeMicroBolgState(intA, D_T_MicroBlogging_Exp.FrozenType.不推荐);
                        if (refInt > 0)
                        {
                              this.Exp_PageWriteLog(Log_Type.other, "微博资料", refInt, "不推荐微博");
                              SetData(0);
                              this.Exp_PageAlter("微博资料不推荐操作成功");
                              return;
                        }
                        else
                        {
                              this.Exp_PageAlter("微博资料不推荐操作失败");
                              return;
                        }
                  });
            }
            //不置顶
            protected void WebUserToolBar1_Button8(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        var strID = Request.Params["HiddenID"].Exp_Trim();
                        var intA = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                        if (intA == null || intA.Count <= 0)
                        {
                              this.Exp_PageAlter("没有找到可以不置顶的信息");
                              return;
                        }

                        var refInt = _Dal.ChangeMicroBolgState(intA, D_T_MicroBlogging_Exp.FrozenType.不置顶);
                        if (refInt > 0)
                        {
                              this.Exp_PageWriteLog(Log_Type.other, "微博资料", refInt, "不置顶微博");
                              SetData(0);
                              this.Exp_PageAlter("微博资料不置顶操作成功");
                              return;
                        }
                        else
                        {
                              this.Exp_PageAlter("微博资料不置顶操作失败");
                              return;
                        }
                  });
            }
      }
}
